
resource "alicloud_ram_group" "main" {
  name                         = var.group_name
  comments                     = var.group_comments
  force                        = var.group_force_destroy
}

resource "alicloud_ram_group_policy_attachment" "system" {
  count                     = var.enable_system_policy && length(var.attach_system_policy_name) > 0 ? length(var.attach_system_policy_name) : 0
  policy_name               = element(var.attach_system_policy_name, count.index)
  policy_type               = var.attach_system_policy_type
  group_name                = alicloud_ram_group.main.name
}

resource "alicloud_ram_group_policy_attachment" "custom" {
  count                     = var.enable_custom_policy && length(var.attach_custom_policy_name) > 0 ? length(var.attach_custom_policy_name) : 0
  policy_name               = element(var.attach_custom_policy_name, count.index)
  policy_type               = var.attach_custom_policy_type
  group_name                = alicloud_ram_group.main.name
}